/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.srcptit.trainning.huongpq.btvn2;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Admin_Pro
 */
public class Bai10 {

    public static boolean kTraNguyenTo(long k) {
        if (k <= 1) {
            return false;
        }
        if (k != 2 && k % 2 == 0) {
            return false;
        }
        double m = Math.sqrt(k);
        long i;
        for (i = 3; i < m; i += 2) {
            if (k % i == 0) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        File f = new File("bai 10.txt");
        try {
            f.createNewFile();
            FileReader fr = new FileReader(f);
            BufferedReader br = new BufferedReader(fr);
            String a;
            String nTo = "";
            int d = 0;
            while ((a = br.readLine()) != null) {
                StringTokenizer s = new StringTokenizer(a);
                int t;
                while (s.hasMoreTokens()) {
                    try {
                        t = Integer.parseInt(s.nextToken());
                        if (kTraNguyenTo(t) && nTo.indexOf(t + "") == -1) {
                            nTo = t + " ";
                            d++;
                            System.out.println(t);
                        }
                    } catch (Exception e) {
                    }
                }
                System.out.println("tong so so nguyen to khac nhau la: " + d);
            }
        } catch (IOException ex) {
            Logger.getLogger(Bai10.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}
